﻿<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>Three框架</title>
    <script src="js/three.js"></script>
    <style type="text/css">
        div#canvas-frame {
            border: none;
            cursor: pointer;
            width: 100%;
            height: 600px;
            background-color: #EEEEEE;
        }
    </style>
    <script>
        var renderer;
        function initThree() {
            width = document.getElementById('canvas-frame').clientWidth;
            height = document.getElementById('canvas-frame').clientHeight;
            renderer = new THREE.WebGLRenderer({
                antialias: true
            });
            renderer.setSize(width, height);
            document.getElementById('canvas-frame').appendChild(renderer.domElement);
            renderer.setClearColor(0x000000, 1.0);
        }

        var camera;
        function initCamera() {
            camera = new THREE.PerspectiveCamera(45, width / height, 1, 10000);
            camera.position.x = 1000;
            camera.position.y = 1000;
            camera.position.z = 2000;
            camera.up.x = 0;
            camera.up.y = 1;
            camera.up.z = 0;
            camera.lookAt({
                x: 0,
                y: 0,
                z: 0
            });
        }

        var scene;
        function initScene() {
            scene = new THREE.Scene();
            var axes = new THREE.AxisHelper(100000);
            scene.add(axes);

        }

        var light;
        function initLight() {
            // A start
            // 第二个参数是光源强度，你可以改变它试一下
            light = new THREE.DirectionalLight(0xFF0000, 1);
            // 位置不同，方向光作用于物体的面也不同，看到的物体各个面的颜色也不一样
            light.position.set(500, 200, 500);
            scene.add(light);
            var helper = new THREE.DirectionalLightHelper(light, 5);
            scene.add(helper);
            // A end
        }

        var cube;
        function initObject() {
            var geometry = new THREE.CubeGeometry(200, 100, 50, 4, 4);
            var material = new THREE.MeshLambertMaterial({ color: 0xFFFFFF });
            var mesh = new THREE.Mesh(geometry, material);
            mesh.position.set(0, 0, 0);
            scene.add(mesh);
        }

        function threeStart() {
            initThree();
            initCamera();
            initScene();
            initLight();
            initObject();
            renderer.clear();
            renderer.render(scene, camera);
        }

    </script>
</head>

<body onload="threeStart();">
    <div id="canvas-frame"></div>
</body>

</html>